//index.js
//获取应用实例
const { globalData } = getApp();

const imageDir = "../../assets/images";
const topTipicDir = imageDir + "/top-topic";
const topicImageDir = imageDir + "/topic";

Page({
  data: {

    topNavList: [
        {
            title: "皮尔特商品",
            url: "/pages/exclusive-shop/index",
            img: `${topTipicDir}/monopoly.png`,
        },
      {
        title: "用户质保",
        url: "/pages/my-quality-info/index",
        img: `${topTipicDir}/quality.png`,
      },
      {
        title: "装修店铺",
        url: "/pages/product-center-page/product-center?merchant_id=",
        img: `${topTipicDir}/mall.png`,
}, 
    //   {
    //     title: "水电管家",
    //     url: "/pages/news/news",
    //     img: `${topTipicDir}/activity.png`,
    //   },
    {
        title: "安装维修",
        url:
          "/pages/installation-maintenance/installation-maintenance?merchant_id=plantform",
        img: `${topicImageDir}/setup.png`,
      },
    ],
    subjoinNavList: [
      [
        {
          title: "装修知识",
          url: "/pages/decoration-knowledge/knowledge",
          img: `${topicImageDir}/decoration-knowledge.png`,
        },
        {
          title: "装修公司",
          url: "/pages/company/company",
          img: `${topicImageDir}/decoration-company.png`,
        },
        {
          title: "设计案例",
          url: "/pages/designer-case/designer-case",
          img: `${topicImageDir}/case.png`,
        },
        {
          title: "设计师",
          url: "/pages/designer/designer",
          img: `${topicImageDir}/designer.png`,
        },
        {
          title: "安装维修",
          url:
            "/pages/installation-maintenance/installation-maintenance?merchant_id=plantform",
          img: `${topicImageDir}/setup.png`,
        },
    //     {
    //     title: "水电管家",
    //     url: "/pages/news/news",
    //     img: `${topTipicDir}/activity.png`,
    //   },
      ],
      [
        {
          title: "产品知识",
          url: "/pages/video-list/video-list?type=video_type_cpzsjj",
          img: `${topicImageDir}/product-knowledge.png`,
        },
        {
          title: "商学院",
          url: "/pages/video-list/video-list?type=video_type_sxy",
          img: `${topicImageDir}/commercial-college.png`,
        },
        {
          title: "回放视频",
          url: "/pages/live-back/live-back",
          img: `${topicImageDir}/play-back.png`,
        },
        {
          title: "短视频",
          url: "/pages/short-video-list/video-list?type=video_type_dsp",
          img: `${topicImageDir}/video.png`,
        },
        {
          title: '全部', 
          url: '/pages/is-building/index?title=全部', 
          img: `${topicImageDir}/all.png`}
      ],
    ],
    bannerList: [
      // {id: 1, image_path: '../../assets/images/test/banner.png'},
      // {id: 2, image_path: '../../assets/images/test/banner.png'},
      // {id: 3, image_path: '../../assets/images/test/banner.png'},
    ],
    noticeList: [
      // {title: '双11购物节 地产装修业抢收忙'},
      // {title: '家居全品类年度钜惠'}
    ],
    adList: [],
    typeList: [],
  },
  
  noticeTabHandle(event) {
    const { index } = event.currentTarget.dataset;
    const data = this.data.noticeList[index];
    wx.navigateTo({
      url: `/pages/notice-detail/notice-detail?id=${data.id}`,
    });
  },
  requestData() {
    Promise.all([
      wx.ajax.post("queryBannerList.action", {}, true),
      wx.ajax.post("queryNoticeList.action", {}, false),
      wx.ajax.post("queryBannerList.action?type=2", {}, false),
      wx.ajax.post(
        "queryProductIndexPage.action",
        { other_type_belong: 1 },
        false
      ),
    ]).then(([bannerRes, noticeRes, adRes, productRes]) => {
      let typeList = [];

      if (productRes.result) {
        productRes.result.forEach((item) => {
          if (item.productInfoList && item.productInfoList.length > 0) {
            typeList.push({
              ...item,
              productList: item.productInfoList.map((product) => {
                return {
                  ...product,
                  head_img: globalData.imageUrl + product.head_img,
                };
              }),
            });
          }
        });
      }

      this.setData({
        bannerList: (bannerRes.result || []).map((item) => {
          return {
            ...item,
            image_path: globalData.imageUrl + item.image_path,
          };
        }),
        noticeList: noticeRes.result || [],
        adList: (adRes.result || []).map((item) => {
          return {
            ...item,
            image_path: globalData.imageUrl + item.image_path,
          };
        }),
        typeList,
      });
    });
  },
  onLoad: function () {
    this.requestData();
    // wx.showShareMenu({
    //   withShareTicket: true,
    //   menus: ['shareAppMessage', 'shareTimeline']
    // })
  },
  onShareTimeline() {
    return {
      path: `/pages/index/index`,
    };
  },
  onShareAppMessage() {
    return {
      // path: `/pages/index/index?merchantId=plantform&type=7&user_id=${globalData.userInfo.user_id}`,
      path: `/pages/index/index`,
    };
  },
});
